home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / ReplaceDialog.java < prev    next >
Text File  |  1998-11-02  |  6KB  |  192 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class ReplaceDialog extends Dialog {
  8.     Frame theJavaPadFrame;
  9.     
  10.     public ReplaceDialog(Frame parent, boolean modal)
  11.     {
  12.         super(parent, modal);
  13.         theJavaPadFrame = parent;
  14.         // This code is automatically generated by Visual Cafe when you add
  15.         // components to the visual environment. It instantiates and initializes
  16.         // the components. To modify the code, only use code syntax that matches
  17.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  18.         // parse your Java file into its visual environment.
  19.         //{{INIT_CONTROLS
  20.         setLayout(null);
  21.         setBackground(java.awt.Color.lightGray);
  22.         setSize(278,107);
  23.         setVisible(false);
  24.         label1.setText("Find");
  25.         add(label1);
  26.         label1.setBounds(7,12,28,24);
  27.         add(m_findText);
  28.         m_findText.setBounds(60,14,124,25);
  29.         add(m_replaceText);
  30.         m_replaceText.setBounds(60,46,124,25);
  31.         label2.setText("Replace");
  32.         add(label2);
  33.         label2.setBounds(3,47,48,21);
  34.         m_caseSencb.setLabel("Case Sensitive");
  35.         add(m_caseSencb);
  36.         m_caseSencb.setBounds(1,77,113,24);
  37.         m_replacebtn.setActionCommand("button");
  38.         m_replacebtn.setLabel("Replace");
  39.         add(m_replacebtn);
  40.         m_replacebtn.setBounds(196,5,66,21);
  41.         m_repAllbtn.setActionCommand("button");
  42.         m_repAllbtn.setLabel("Replace All");
  43.         add(m_repAllbtn);
  44.         m_repAllbtn.setBounds(196,42,66,21);
  45.         m_cancelbtn.setActionCommand("button");
  46.         m_cancelbtn.setLabel("Cancel");
  47.         add(m_cancelbtn);
  48.         m_cancelbtn.setBounds(196,79,66,21);
  49.         setTitle("Dialog2");
  50.         //}}
  51.  
  52.         //{{REGISTER_LISTENERS
  53.         SymWindow aSymWindow = new SymWindow();
  54.         addWindowListener(aSymWindow);
  55.         SymAction lSymAction = new SymAction();
  56.         m_replacebtn.addActionListener(lSymAction);
  57.         m_repAllbtn.addActionListener(lSymAction);
  58.         m_cancelbtn.addActionListener(lSymAction);
  59.         //}}
  60.     }
  61.     
  62.     public void addNotify()
  63.     {
  64.         // Record the size of the window prior to calling parents addNotify.
  65.         Dimension d = getSize();
  66.         
  67.         super.addNotify();
  68.  
  69.         if (fComponentsAdjusted)
  70.             return;
  71.  
  72.         // Adjust components according to the insets
  73.         Insets insets = getInsets();
  74.         setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
  75.         Component components[] = getComponents();
  76.         for (int i = 0; i < components.length; i++)
  77.         {
  78.             Point p = components[i].getLocation();
  79.             p.translate(insets.left, insets.top);
  80.             components[i].setLocation(p);
  81.         }
  82.         fComponentsAdjusted = true;
  83.     }
  84.  
  85.  
  86.     // Used for addNotify check.
  87.     boolean fComponentsAdjusted = false;
  88.  
  89.  
  90.     public ReplaceDialog(Frame parent, String title, boolean modal, FindReplace fr)
  91.     {
  92.         this(parent, modal);
  93.         setTitle(title);
  94.         m_replace = fr;
  95.         m_findText.setText(m_replace.getFind());
  96.         m_replaceText.setText(m_replace.getReplace());
  97.         m_caseSencb.setState(m_replace.isCase());
  98.         
  99.     }
  100.  
  101.  
  102.  
  103.     //{{DECLARE_CONTROLS
  104.     java.awt.Label label1 = new java.awt.Label();
  105.     java.awt.TextField m_findText = new java.awt.TextField();
  106.     java.awt.TextField m_replaceText = new java.awt.TextField();
  107.     java.awt.Label label2 = new java.awt.Label();
  108.     java.awt.Checkbox m_caseSencb = new java.awt.Checkbox();
  109.     java.awt.Button m_replacebtn = new java.awt.Button();
  110.     java.awt.Button m_repAllbtn = new java.awt.Button();
  111.     java.awt.Button m_cancelbtn = new java.awt.Button();
  112.     //}}
  113.     FindReplace m_replace;
  114.  
  115.     class SymWindow extends java.awt.event.WindowAdapter
  116.     {
  117.         public void windowClosing(java.awt.event.WindowEvent event)
  118.         {
  119.             Object object = event.getSource();
  120.             if (object == ReplaceDialog.this)
  121.                 ReplaceDialog_WindowClosing(event);
  122.         }
  123.     }
  124.     
  125.     void ReplaceDialog_WindowClosing(java.awt.event.WindowEvent event)
  126.     {
  127.         ReplaceDialog_WindowClosing_Interaction1(event);
  128.     }
  129.     
  130.     void ReplaceDialog_WindowClosing_Interaction1(java.awt.event.WindowEvent event)
  131.     {
  132.         try {
  133.             this.dispose();
  134.         } catch (Exception e) {
  135.         }
  136.     }
  137.  
  138.     class SymAction implements java.awt.event.ActionListener
  139.     {
  140.         public void actionPerformed(java.awt.event.ActionEvent event)
  141.         {
  142.             Object object = event.getSource();
  143.             if (object == m_replacebtn)
  144.                 mReplacebtn_ActionPerformed(event);
  145.             else if (object == m_repAllbtn)
  146.                 mRepAllbtn_ActionPerformed(event);
  147.             else if (object == m_cancelbtn)
  148.                 mCancelbtn_ActionPerformed(event);
  149.         }
  150.     }
  151.  
  152.     void mReplacebtn_ActionPerformed(java.awt.event.ActionEvent event)
  153.     {
  154.         m_replace.setReplace(m_replaceText.getText().trim());
  155.         m_replace.setFind(m_findText.getText().trim());
  156.         m_replace.setCase(m_caseSencb.getState());
  157.         m_replace.setReplaceAll(false);
  158.         m_replace.setReplaceIt(false);
  159.         m_replace.setIndex(m_replace.getBody().getSelectionStart());
  160.         dispose();
  161.         try{Thread.sleep(250);}catch(InterruptedException ie){}
  162.         (new ReplaceConfirmDialog(theJavaPadFrame, "Replace Confirm", true, m_replace)).show();
  163.         
  164.     }
  165.  
  166.     void mRepAllbtn_ActionPerformed(java.awt.event.ActionEvent event)
  167.     {
  168.         FindReplaceEngine fre;
  169.         fre = new FindReplaceEngine(m_replace);
  170.         m_replace.setReplace(m_replaceText.getText());
  171.         m_replace.setFind(m_findText.getText());
  172.         m_replace.setReplaceAll(true);
  173.         m_replace.setReplaceIt(true);
  174.         m_replace.setCase(m_caseSencb.getState());
  175.         dispose();
  176.         fre.ReplaceAll();
  177.     }
  178.  
  179.     void mCancelbtn_ActionPerformed(java.awt.event.ActionEvent event)
  180.     {
  181.         mCancelbtn_ActionPerformed_Interaction1(event);
  182.     }
  183.     
  184.     void mCancelbtn_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  185.     {
  186.         try {
  187.             this.dispose();
  188.         } catch (Exception e) {
  189.         }
  190.     }
  191. }
  192.